<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">文本短信发送任务列表</ui:define>
    <ui:define name="content">
        <h:form id="taskSendForm">

            <p:dialog id="editSmsSendTaskDialog" rendered="#{smsSendTaskBean.smsSendTask != null}"
                      header="编辑短信历史任务" position="center" widgetVar="editSmsSendTaskDialogWidgeVar" modal="true"
                      width="25%" height="70%" responsive="true" resizable="false">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">

                    <p:outputLabel for="registerCount" value="注册数"/>
                    <p:inputNumber id="registerCount" value="#{smsSendTaskBean.smsSendTask.registerCount}"
                                   styleClass="autoWidthCalendar" decimalPlaces="0"/>

                    <p:outputLabel for="loanCount" value="放贷数"/>
                    <p:inputNumber id="loanCount" value="#{smsSendTaskBean.smsSendTask.loanCount}"
                                   styleClass="autoWidthCalendar" decimalPlaces="0"/>

                    <p:outputLabel for="income" value="收入"/>
                    <p:inputNumber id="income" value="#{smsSendTaskBean.smsSendTask.income}"
                                   styleClass="autoWidthCalendar" decimalPlaces="0"/>

                    <p:outputLabel for="remark" value="备注"/>
                    <p:inputTextarea id="remark" value="#{smsSendTaskBean.smsSendTask.remark}" rows="5"/>

                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:commandButton value="确定修改" actionListener="#{smsSendTaskBean.onEdit()}"
                                     process="editSmsSendTaskDialog" update="@form"/>
                </div>
            </p:dialog>

            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>

                        <p:columnToggler datasource="smsSendTaskDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         update="@form"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         actionListener="#{smsSendTaskBean.onReset}"
                                         process="@this"
                                         update="@form"/>
                        <p:button value="返回" icon="fa fa-reply-all" href="#{currentUserBean.back}"></p:button>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card ui-g-12">
                            <div class="ui-g-1">
                                <p:outputLabel value="名称"/>
                            </div>
                            <div class="ui-g-5">
                                <p:inputText value="#{smsSendTaskBean.$.name}"/>
                            </div>
                            <div class="ui-g-1">
                                <p:outputLabel value="内容"/>
                            </div>
                            <div class="ui-g-5">
                                <p:inputText value="#{smsSendTaskBean.$.content}"/>
                            </div>
                            <div class="ui-g-1">
                                <p:outputLabel value="状态"/>
                            </div>
                            <div class="ui-g-5">
                                <p:selectOneMenu
                                        value="#{smsSendTaskBean.$.status}" filter="true"
                                        filterMatchMode="contains">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                                  noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{smsSendTaskBean.dictionaries[DictionaryCode.SMS_SEND_STATUS]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>
                            </div>
                            <div class="ui-g-1">
                                <p:outputLabel value="短信平台"/>
                            </div>
                            <div class="ui-g-5">
                                <p:selectOneMenu
                                        value="#{smsSendTaskBean.$.platformChannel}" filter="true"
                                        filterMatchMode="contains">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                                  noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{smsSendTaskBean.dictionaries[DictionaryCode.SMS_PLATFORM_CHANNEL]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>
                            </div>
                            <div class="ui-g-1">
                                <p:outputLabel value="执行时间"/>
                            </div>
                            <div class="ui-g-5">
                                <p:calendar value="#{smsSendTaskBean.$.executeTimeStart}"
                                            styleClass="autoWidthCalendar"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"
                                            readonlyInput="true"/>
                                <span>—</span>
                                <p:calendar value="#{smsSendTaskBean.$.executeTimeEnd}"
                                            styleClass="autoWidthCalendar"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"
                                            readonlyInput="true"/>
                            </div>
                            <div class="ui-g-1">
                                <p:outputLabel value="短信数量"/>
                            </div>
                            <div class="ui-g-5">
                                <p:inputNumber value="#{smsSendTaskBean.$.countStart}"
                                               styleClass="autoWidthCalendar"
                                               decimalPlaces="0"/>
                                <span>—</span>
                                <p:inputNumber value="#{smsSendTaskBean.$.countEnd}"
                                               styleClass="autoWidthCalendar"
                                               decimalPlaces="0"/>
                            </div>
                        </div>
                        <div class="card ui-g-12">
                            <p:dataTable id="smsSendTaskDataTable"
                                         style="width: 100%"
                                         var="smsSendTask"
                                         value="#{smsSendTaskBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection="#{smsSendTaskBean.selectedRecords}"
                                         resizableColumns="true">

                                <p:column headerText="操作" width="9%">
                                    <p:splitButton icon="fa fa-eye"
                                                   action="#{smsSendTaskBean.onViewCondition(smsSendTask.id)}"
                                                   process="@this">
                                        <f:setPropertyActionListener
                                                value="/views/family/user-info/send-sms/sms-send-task.xhtml"
                                                target="#{currentUserBean.back}"/>

                                        <p:menuitem value="取消" icon="fa fa-remove"
                                                    action="#{smsSendTaskBean.onCancel(smsSendTask.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{smsSendTask.status == 0 or smsSendTask.status == 1 or smsSendTask.status == 6 or smsSendTask.status == 7}">
                                            <p:confirm header="提示信息" message="确定取消?" icon="ui-icon-alert"/>
                                        </p:menuitem>

                                        <p:menuitem value="编辑" icon="fa fa-edit"
                                                    actionListener="#{smsSendTaskBean.onSelect(smsSendTask.id)}"
                                                    oncomplete="PF('editSmsSendTaskDialogWidgeVar').show()"
                                                    process="@this" update="@form"/>

                                        <p:menuitem value="重新发送" icon="fa fa-repeat"
                                                    actionListener="#{smsSendTaskBean.onResend(smsSendTask.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{smsSendTask.status == 3 or smsSendTask.status == 7}"/>

                                        <p:menuitem value="恢复发送" icon="fa fa-repeat"
                                                    actionListener="#{smsSendTaskBean.onResend(smsSendTask.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{smsSendTask.status == 4}"/>

                                        <p:menuitem value="错误信息" icon="fa fa-warning"
                                                    actionListener="#{smsSendTaskBean.onViewError(smsSendTask.id)}"
                                                    oncomplete="PF('errorReasonDialogWidgeVar').show();"
                                                    update=":taskSendForm:errorReasonDialog"
                                                    rendered="#{smsSendTask.status == 3}"/>

                                        <p:menuitem value="短信平台返回结果" icon="fa fa-envelope-o"
                                                    actionListener="#{smsSendTaskBean.onViewResult(smsSendTask.id)}"
                                                    oncomplete="PF('smsPlatformResultDialogWidgeVar').show();"
                                                    update=":taskSendForm:smsPlatformResultDialog"
                                                    rendered="#{smsSendTask.status == 2  or smsSendTask.status == 3}"/>

                                    </p:splitButton>
                                </p:column>
								
								<p:column headerText="发送任务ID">
                                    <h:outputText value="#{smsSendTask.id}"/>
                                </p:column>
                                <p:column headerText="名称">
                                    <h:outputText value="#{smsSendTask.name}"/>
                                </p:column>
                                <p:column headerText="执行时间">
                                    <h:outputText value="#{smsSendTask.executeTime}"/>
                                </p:column>
                                <p:column headerText="内容">
                                    <h:outputText value="#{smsSendTask.content}"/>
                                </p:column>
                                 <p:column headerText="短连接">
                                    <h:outputText value="#{smsSendTask.shortLink}"/>
                                </p:column>
                                <p:column headerText="状态">
                                    <h:outputText
                                            value="#{smsSendTaskBean.translate(DictionaryCode.SMS_SEND_STATUS,smsSendTask.status)}"/>
                                </p:column>
                                <div class="ui-g-4">
                                    <p:column headerText="运营商">
                                    <p:selectManyButton
                                            value="#{smsSendTask.telecomOperators}"
                                            disabled="true">
                                        <f:selectItem itemLabel="移动" itemValue="0"/>
                                        <f:selectItem itemLabel="联通" itemValue="1"/>
                                        <f:selectItem itemLabel="电信" itemValue="2"/>
                                    </p:selectManyButton>
                                </p:column>
                                </div>
                                <div class="ui-g-4">
                                    <p:column headerText="用户类型">
                                    <p:selectManyButton
                                            value="#{smsSendTask.userTypes}"
                                            disabled="true">
                                        <f:selectItem itemLabel="注册用户" itemValue="0"/>
                                        <f:selectItem itemLabel="登记未注册用户" itemValue="1"/>
                                    </p:selectManyButton>
                                </p:column>
                                </div>
                                <p:column headerText="短信平台渠道">
                                    <h:outputText
                                            value="#{smsSendTaskBean.translate(DictionaryCode.SMS_PLATFORM_CHANNEL,smsSendTask.platformChannel)}"/>
                                </p:column>
                                <p:column headerText="短信数量">
                                    <h:outputText value="#{smsSendTask.count}"/>
                                </p:column>
                                <!--<p:column headerText="成本">
                                    <h:outputText value="#{smsSendTask.cost}"/>
                                </p:column>
                                <p:column headerText="注册数">
                                    <h:outputText value="#{smsSendTask.registerCount}"/>
                                </p:column>
                                <p:column headerText="放贷数">
                                    <h:outputText value="#{smsSendTask.loanCount}"/>
                                </p:column>
                                <p:column headerText="收入">
                                    <h:outputText value="#{smsSendTask.income}"/>
                                </p:column>
                                <p:column headerText="备注">
                                    <h:outputText value="#{smsSendTask.remark}"/>
                                </p:column>-->
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
            <p:dialog id="errorReasonDialog" header="任务异常信息" widgetVar="errorReasonDialogWidgeVar"
                      modal="true"
                      resizable="false"
                      closable="true"
                      width="1024"
                      height="400"
                      responsive="true">
                <div class="ui-g ui-fluid">
                    <div class="ui-g-12">
                        <p:inputTextarea rows="20" value="#{smsSendTaskBean.taskErrorReason}" readonly="true"/>
                    </div>
                </div>
            </p:dialog>
            <p:dialog id="smsPlatformResultDialog" header="短信平台返回信息" widgetVar="smsPlatformResultDialogWidgeVar"
                      modal="true"
                      resizable="false"
                      closable="true"
                      width="1024"
                      height="400"
                      responsive="true">
                <div class="ui-g ui-fluid">
                    <div class="ui-g-12">
                        <p:inputTextarea rows="20" value="#{smsSendTaskBean.smsPlatformResult}" readonly="true"/>
                    </div>
                </div>
            </p:dialog>
        </h:form>
    </ui:define>
</ui:composition>
